package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;
import com.localjoycommunity.cpdj.project.system.domain.SysOption;
import com.localjoycommunity.cpdj.project.system.service.ISysOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 试题选项Controller
 *
 * @author leepandar
 * @date 2020-11-01
 */
@RestController
@RequestMapping("/system/option")
public class SysOptionController extends BaseController {
    @Autowired
    private ISysOptionService sysOptionService;

    /**
     * 查询试题选项列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysOption sysOption) {
        startPage();
        List<SysOption> list = sysOptionService.selectSysOptionList(sysOption);
        return getDataTable(list);
    }

    /**
     * 导出试题选项列表
     */
    @Log(title = "试题选项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysOption sysOption) {
        List<SysOption> list = sysOptionService.selectSysOptionList(sysOption);
        ExcelUtil<SysOption> util = new ExcelUtil<SysOption>(SysOption.class);
        return util.exportExcel(list, "option");
    }

    /**
     * 获取试题选项详细信息
     */
    @GetMapping(value = "/{optionId}")
    public AjaxResult getInfo(@PathVariable("optionId") Long optionId) {
        return AjaxResult.success(sysOptionService.selectSysOptionById(optionId));
    }

    /**
     * 新增试题选项
     */
    @Log(title = "试题选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOption sysOption) {
        return toAjax(sysOptionService.insertSysOption(sysOption));
    }

    /**
     * 修改试题选项
     */
    @Log(title = "试题选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOption sysOption) {
        return toAjax(sysOptionService.updateSysOption(sysOption));
    }

    /**
     * 删除试题选项
     */
    @Log(title = "试题选项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{optionIds}")
    public AjaxResult remove(@PathVariable Long[] optionIds) {
        return toAjax(sysOptionService.deleteSysOptionByIds(optionIds));
    }
}
